package com.rat.datadictionary.util;


import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

/**
 * @Description: 设置计划EXCEL模板具体Sheet样式
 * @Param:
 * @Return:
 * @Author: Howe
 * @Date: 2020/6/28 14:09
 */
public class TemplateSetSheetStyle {


    /**
     * @Description: 设置边框居左
     * @Param:
     * @Return:
     * @Author: Howe
     * @Date: 2020/6/28 14:08
     */
    public static void setSheetLeftFrameStyle(XSSFWorkbook wb, XSSFSheet sheet, int startRow, int endRow, int startCol, int endCol) {

        XSSFCellStyle cellStyle = wb.createCellStyle();

        for (int i = startRow; i < endRow; i++) {
            Row row = sheet.createRow(i);
            row.setHeightInPoints(20);
            for (int j = startCol; j < endCol; j++) {
                Cell cell = row.createCell(j);
                setBorder(cellStyle);
                cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
                cellStyle.setAlignment(HorizontalAlignment.LEFT);
                cellStyle.setLocked(false);
                cell.setCellStyle(cellStyle);
            }
        }
    }



    /**
    * @Description: 设置边框
    * @Param:
    * @Return:
    * @Author: Howe
    * @Date: 2021/1/7 20:07
    **/
    private static void setBorder(XSSFCellStyle cellStyle) {
        cellStyle.setBorderTop(BorderStyle.THIN); // 上边框
        cellStyle.setBorderLeft(BorderStyle.THIN); // 左边框
        cellStyle.setBorderRight(BorderStyle.THIN); // 右边框
        cellStyle.setBorderBottom(BorderStyle.THIN); // 下边框
    }


    /**
    * @Description: 设置边框居中
    * @Param:
    * @Return:
    * @Author: Howe
    * @Date: 2021/1/7 20:06
    **/
    public static void setSheetCenterFrameStyle(XSSFWorkbook wb, XSSFSheet sheet, int startRow, int endRow, int startCol, int endCol) {

        XSSFCellStyle cellStyle = wb.createCellStyle();

        for (int i = startRow; i < endRow; i++) {
            Row row = sheet.createRow(i);
            row.setHeightInPoints(20);
            for (int j = startCol; j < endCol; j++) {
                Cell cell = row.createCell(j);
                setBorder(cellStyle);
                cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
                cellStyle.setAlignment(HorizontalAlignment.CENTER);
                cellStyle.setLocked(false);
                cell.setCellStyle(cellStyle);
            }
        }
    }

    /**
     * @Description: 设置提示字体
     * @Param:
     * @Return:
     * @Author: Howe
     * @Date: 2020/6/28 14:08
     */
    public static Font getTitleFont(XSSFWorkbook wb) {
        Font font = wb.createFont();
        font.setBold(true);
        font.setFontHeightInPoints((short) 12);
        return font;

    }

    /**
     * @Description: 设置提示字体
     * @Param:
     * @Return:
     * @Author: Howe
     * @Date: 2020/6/28 14:08
     */
    public static Font getInstructionsFont(XSSFWorkbook wb) {
        Font font = wb.createFont();
        font.setColor(Font.COLOR_RED);
        return font;

    }


}